//
//  YMBaseAlertView.m
//  YMMedical
//
//  Created by y s on 2023/7/17.
//

#import "YMBaseAlertView.h"
#import "AppDelegate.h"

@interface YMBaseAlertView ()


@end

@implementation YMBaseAlertView

- (instancetype)init{
    self = [super init];
    if (self) {
        [self initUI];
    }
    return self;
}

#pragma mark -- UI
- (void)initUI{
    self.backgroundColor = [SUIUtil colorOf:0x000000 alpha:0.6];
    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    [self addSubview:self.vAlert];
    
    [self.vAlert mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.mas_equalTo([SFitUtil fit:330]);
    }];
}

- (void)show{
    UIWindow *keyWindow = [SThemeUtil keyWindow];
    for (UIView *item in keyWindow.subviews) {
        if ([item isKindOfClass:[self class]]){
            return;
        }
    }
    [keyWindow addSubview:self];
    self.alpha = 0;
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 1;
    }];
}
- (void)showInView:(UIView *)view{
    if (view == nil){
        return;
    }
    for (UIView *item in view.subviews) {
        if ([item isKindOfClass:[self class]]){
            return;
        }
    }
    [view addSubview:self];
    self.alpha = 0;
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 1;
    }];
}

- (void)dismiss{
    [self removeFromSuperview];
}

#pragma mark -- setter and getter
- (UIView *)vAlert{
    if (_vAlert == nil){
        _vAlert = [[UIView alloc] init];
        _vAlert.backgroundColor = STheme.D9;
        _vAlert.clipsToBounds = YES;
        _vAlert.layer.cornerRadius = [SFitUtil fit:8];
    }
    return _vAlert;
}

@end
